<template>
  <div>
    <a-modal v-model:visible="visible">
      <template #title> 存放地点管理 </template>
      <a-form :model="form" :rules="rules" ref="formRef" @submit="handleSubmit">
        <a-form-item field="manage_address" label="存放地点">
          <a-input
            v-model="form.manage_address"
            placeholder="请输入存放地点"
            allow-clear
          ></a-input>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" @click="saveProductName">确定</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { saveManageAddress } from '@/api/manage';
import { Message } from '@arco-design/web-vue';

const props = defineProps({
  getManageList: {
    type: Function,
  },
});
const visible = ref(false);
const formRef = ref(null);
const openDialog = (record) => {
  if (record) {
    form.id = record.id;
    form.manage_address = record.manage_address;
  } else {
    form.id = '';
    form.manage_address = '';
  }
  visible.value = true;
};
const form = reactive({
  id: '',
  manage_address: '',
});
const rules = {
  manage_address: [
    {
      required: true,
      message: '请输入存放地点',
    },
  ],
};
const saveProductName = () => {
  formRef.value.validate().then(async (res) => {
    if (res === undefined) {
      const { data, code, message } = await saveManageAddress(form);
      Message.success(message);
      if (code === 200) {
        props.getManageList();
        visible.value = false;
        formRef.value.resetFields();
      }
    }
  });
};
defineExpose({
  openDialog,
});
</script>

<style lang="scss" scoped></style>